package com.sykj.cloud.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sykj.cloud.system.domain.SysParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.log.enums.LogUserType;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.system.domain.OrgSite;
import com.sykj.cloud.system.service.IOrgSiteService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 站点 Controller
 *
 * @author mr.will
 * @date 2021-03-24
 */
@RestController
@RequestMapping("/site")
public class OrgSiteController extends BaseController
{
    @Autowired
    private IOrgSiteService orgSiteService;

    /**
     * 新增站点
     */
    @PreAuthorize(hasPermi = "system:site:add")
    @Log(title = "站点 ", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrgSite orgSite)
    {
        return toAjax(orgSiteService.insertOrgSite(orgSite));
    }

    /**
     * 修改站点
     */
    @PreAuthorize(hasPermi = "system:site:edit")
    @Log(title = "站点 ", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrgSite orgSite)
    {
        return toAjax(orgSiteService.updateOrgSite(orgSite));
    }

    /**
     * 删除站点
     */
    @PreAuthorize(hasPermi = "system:site:remove")
    @Log(title = "站点 ", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(orgSiteService.deleteOrgSiteByIds(guids));
    }

    /**
     * 获取站点 详细信息
     */
    @PreAuthorize(hasPermi = "system:site:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(orgSiteService.getOrgSiteById(guid));
    }

    /**
     * 导出站点 列表
     */
    @PreAuthorize(hasPermi = "system:site:export")
    @Log(title = "站点 ", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrgSite orgSite) throws IOException
    {
        List<OrgSite> list = orgSiteService.listOrgSites(orgSite);
        ExcelUtil<OrgSite> util = new ExcelUtil<OrgSite>(OrgSite.class);
        util.exportExcel(response, list, "site");
    }

    /**
     * 查询站点 列表
     */
    @PreAuthorize(hasPermi = "system:site:list")
    @GetMapping("/list")
    public TableDataInfo list(OrgSite orgSite)
    {
        startPage();
        List<OrgSite> list = orgSiteService.listOrgSites(orgSite);
        return getDataTable(list);
    }

    /**
     * 查询站点信息，下拉框值
     */
    @PreAuthorize(hasPermi = "system:site:list")
    @GetMapping("/list/options")
    public AjaxResult optionList(OrgSite orgSite)
    {
        return AjaxResult.success(orgSiteService.listOrgSites(orgSite));
    }
}
